<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-Control" content="no-cache">
  <meta http-equiv="Expires" content="0">
  <title></title>
  <script src="js/mui.min.js"></script>
  <link href="css/mui.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="css/pos.min.css">
</head>

<body>
  <div class="posbg">
    <div class="btn" id="scan"></div>
  </div>
</body>
<script src="js/flex.js"></script>
<script src="js/jquery-3.4.1.js"></script>
<script>
  var hasToken = false; //token为null,扫二维码不可点击
  // 获取token
  $.ajax({
    type: "GET",
    url: 'https://agreement.ameimeika.com/api/bank/token',
    dataType: 'json',
    success: function (res) {
      if (res.code == 200) {
        if (res.data.token) {
          hasToken = true;
          sessionStorage.setItem("token", res.data.token);
        } else {
          hasToken = false;
          mui.alert("请重新进入应用");
        }
      }
    },
    error: function (err) {
      mui.alert('服务器迷路了...')
    }
  })
  // 点击扫一扫
  $("#scan").click(function () {
    if (hasToken) {
      PosEvent.openCamare()
    }
  })
  // 供第三方调用
  function camareResult(str) {
    var encode = getUrlParam("encode", str);
    sessionStorage.setItem("encode", encode);
    if (getUrlParam("type", str)) {//企业
      location.href = "orderInfo.html"
    } else {
      location.href = 'confirmOrder.html';
    }
  }
  var getUrlParam = function (name, str) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(str) || [, ""])[1].replace(/\+/g, '%20')) || null;
  }
</script>

</html>